package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Transformations
import com.cheyun.netsalev3.bean.order.OrderChooseData
import com.cheyun.netsalev3.bean.order.OrderKeliuData
import com.cheyun.netsalev3.repository.OrderChooseListPageRepository
import com.cheyun.netsalev3.repository.OrderDaoDianListPageRepository
import java.io.Serializable

class ChoiceOrderActivityViewModel(var homeTaskYaoyueRepository: OrderChooseListPageRepository) : BaseViewModel() {
    //到店数据
    var listdata = homeTaskYaoyueRepository.loadAndroidData()
    var networkState = Transformations.switchMap(listdata) {
        homeTaskYaoyueRepository.networkState
    }

    //点击到店列表
    fun onClickDaoDian(view: View, data: OrderChooseData) {
        var content = view.context
        if (content is AppCompatActivity) {
            var intent = Intent()
            intent.putExtra("data", data as Serializable)
            content.setResult(104, intent)
            content.finish()

        }
    }

    fun refresh() {
        homeTaskYaoyueRepository.dataSourceFactory.sourceLiveData.value?.invalidate()
    }
}